package com.sromku.simple.fb.example;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

import com.example.hal.model.Activite;
import com.example.hal.model.ActiviteController;

public class AdresseGetActivity extends Activity {
private List lists = null;
private List listsName = null;
private EditText searchTextAdresse = null;
private ListView listLists;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_adresse);

searchTextAdresse =(EditText) findViewById(R.id.searchTextAdresse);
listLists = (ListView) findViewById(R.id.listAdresse);

searchTextAdresse.addTextChangedListener(new TextWatcher() {
    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub

    	getAdresses();
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub
       
    }
});
getAdresses();

}

final void getAdresses() {

	

    Geocoder gc = new Geocoder(this, Locale.getDefault());  
    List<Address> foundAdresses;
	     try 
   {
	 foundAdresses = gc.getFromLocationName(searchTextAdresse.getText().toString(), 10); 
                if(foundAdresses!=null && foundAdresses.size()>0)
	 {	
                	

listLists.setAdapter(new ArrayAdapter(getBaseContext(),
android.R.layout.simple_list_item_1, foundAdresses));

		/* Address x =foundAdresses.get(0);
		 int latitudeE6 = (int)(x.getLatitude()*1E6);
		 int longitudeE6 = (int)(x.getLongitude()*1E6);
		 GeoPoint point = new GeoPoint(latitudeE6,longitudeE6);
		 overlayitem = new OverlayItem(point, list.get(i)[0], list.get(i)[2]);
		 itemizedoverlay.addOverlay(overlayitem);*/
	  }
	  else
	  {
	//	 System.out.println( j++ +"=="+list.get(i)[0]);
	  }
   } catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
  }
    /*
ActiviteController list = new ActiviteController();
listsName = new ArrayList();
try {
lists = list.getAllActivites();
} catch (Exception e) {
e.printStackTrace();
}
if (lists != null) {

	 Log.i("GetAllActiviteActivity",String.valueOf(lists.size()));
	 Log.i("GetAllActiviteActivity",lists.get(0).getClass().toString());

	 Log.i("GetAllActiviteActivity",lists.get(0).toString());

for (Object o : lists) {
	Activite u=(Activite) o;
if (u != null)
listsName.add(u.getNom() + " " + u.getLogo());
}


//listLists.setTextFilterEnabled(true);

}*/
}
}